package langnstats.project.languagemodel.ngram;

import java.util.ArrayList;
import java.util.Collection;

public class History<T> extends ArrayList<T>{
	private static final long serialVersionUID = 1L;
	
	public History(){ super(); }
	public History(int initSize){ super(initSize); }
	public History(Collection<? extends T> c){ super(c); }
	
	public void trim(int n){
//		try{ 
			while(this.size()>n){ this.remove(0); }
//		}catch(IndexOutOfBoundsException ex){
//			System.out.println("n is "+n);
//			throw ex;
//		}
	}
	
	public boolean equals(Object o){
		if(!(o instanceof History)){ return false; }
		
		History<?> in = (History<?>)o;
		
		if(this.size()!=in.size()){ return false; }
		
		if(this.size()==0){ return true; }
		
		for(int i=0; i<this.size(); i++){
			if(!this.get(i).equals(in.get(i))){ return false; }			
		}
		return true;
	}
	
	
}
